package BufferAndChannel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class demo6 {
    public static void main(String[] args) throws IOException {
        FileInputStream is = new FileInputStream("");
        FileOutputStream os = new FileOutputStream("");

        FileChannel inChannel = is.getChannel();
        FileChannel outChannel = os.getChannel();

        // 获得多个缓冲区，并且放入到缓冲区数组中
        ByteBuffer byteBuffer1 = ByteBuffer.allocate(50);
        ByteBuffer byteBuffer2 = ByteBuffer.allocate(1024);
        ByteBuffer[] byteBuffers = {byteBuffer1, byteBuffer2};

        // 分散读取
        inChannel.read(byteBuffers);

        byteBuffer1.flip();
        byteBuffer2.flip();

        // 聚集写入
        outChannel.write(byteBuffers);
    }
}